<template>
  <div class="app-container">
    <div class="search-box">
      <div class="search-hd">连接池监控</div>
      <el-form
        ref="form"
        :model="searchField"
        label-width="80px"
        :inline="true"
      >
        <el-form-item label="时间范围">
          <el-date-picker
            v-model="searchField.date"
            size="small"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="主机名" size="small">
          <el-input
            placeholder="请输入内容"
            v-model="searchField.hostName"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="状态" size="small">
          <el-input
            placeholder="请输入内容"
            v-model="searchField.status"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-button
          type="success"
          size="small"
          @click="selectSelectived(searchField)"
          >查询</el-button
        >
        <!--<el-button type="success" size="small">导出</el-button>-->
      </el-form>
    </div>
    <div class="main-box">
      <div class="main-hd">连接池监控</div>
      <el-table
        v-loading="loading"
        :data="list"
        stripe
        max-height="500"
        fit
        highlight-current-row
      >
        <el-table-column label="序号" width="95" align="center">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column
          label="主机名"
          prop="hostName"
          align="center"
        ></el-table-column>
        <!--        <el-table-column label="连接地址" prop="clientNetAddress" align="center"></el-table-column>-->
        <!--        <el-table-column label="终端名" prop="programName" align="center"></el-table-column>-->
        <el-table-column
          label="开始使用时间"
          prop="loginTime"
          align="center"
        ></el-table-column>
        <el-table-column
          label="最后使用时间"
          prop="loginTime"
          align="center"
        ></el-table-column>
        <el-table-column
          label="状态"
          prop="status"
          align="center"
        ></el-table-column>
      </el-table>
      <div class="page-box">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="searchField.page"
          :page-sizes="[10, 15, 20, 25, 30, 50]"
          :page-size="searchField.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <el-dialog title="告警配置" :visible.sync="dialogVisible" width="500px">
      <el-checkbox-group v-model="checkList">
        <el-checkbox label="deadly">致命错误</el-checkbox>
        <el-checkbox label="serious">严重错误</el-checkbox>
        <el-checkbox label="commonly">一般错误</el-checkbox>
        <el-checkbox label="general">普通错误</el-checkbox>
      </el-checkbox-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <!-- <el-button type="primary" @click="saveSet">确 定</el-button>-->
        <el-button type="primary" @click="updatexxObject(form)"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getSourceList } from "@/api/table";

export default {
  data() {
    return {
      list: null,
      loading: true,
      total: 10,
      searchField: {
        hostName: "",
        status: "",
        startTime: "",
        endTime: "",
        page: 1,
        limit: 15,
        date: "",
      },
      checkedId: "",
      checkList: [],
      dialogVisible: false,
      dialogFormVisible: false,
      dialogUpdateFormVisible: false,
      form: {
        id: "",
        pid: "",
        name: "",
        type: "",
        configs: "",
        contact: "",
        isDelete: 0,
        address: "",
        extention: "",
        serialVersionUID: 0,
        mProject: {
          id: "",
          name: "",
          server: "",
          db: "",
          mission: "",
          service: "",
          number: "",
          provider: "",
          tel: "",
          extention: "",
        },
      },
      formLabelWidth: "120px",
    };
  },
  created() {
    this.initListData();
  },
  methods: {
     //搜索
      selectSelectived(searchField) {
      console.log(searchField);
        getSourceList(this.searchField).then((res) => {
         this.$message.success("查询成功");
          this.list = res.data.data.rows;
          this.total = res.data.data.total;
          this.loading = false;
      });
    },
    // 配置
    set(id) {
      this.checkedId = id;
      this.dialogVisible = true;
    },
    saveSet() {
      console.log(this.checkList, this.checkedId);
      this.dialogVisible = false;
    },
    initListData() {
      this.loading = true;
      getSourceList(this.searchField).then((res) => {
        console.log(res);
        this.list = res.data.data.rows;
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.searchField.limit = val;
      this.pagingQuery();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      console.log(`当前页: ` + val);
      this.searchField.page = val;
      this.pagingQuery();
    },
    // 分页查询函数
    pagingQuery: function () {
      getSourceList(this.searchField).then((res) => {
        this.list = res.data.data.rows;
        this.loading = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.redColor {
  color: red;
}

.search-box {
  margin-bottom: 15px;

  .search-hd {
    border-left: 2px solid #00a73c;
    padding: 10px;
    margin-bottom: 10px;
  }

  .search-bd {
    .el-button--small {
      margin-top: 3px;
    }
  }
}

.main-box {
  .main-hd {
    height: 40px;
    line-height: 40px;
    background: #00a73c;
    color: #fff;
    padding-left: 10px;
  }

  .page-box {
    padding: 10px;
    text-align: center;
  }
}
</style>
